<% layout('/layout/default.html', {title: '业务表详情', libs: ['validate','icheck']}){ %>
<div class="main-content">
    <div class="card-header">
        <h3><i class="fas fa-cog"></i> ${fieldAuthorize.fieldName} 字段配置</h3>
    </div>
    <form id="inputForm" action="${ctx}/act/flowForm/saveAuthroize" method="post" class="form-horizontal">
        <div class="card-body">
            <div class="form-group row">
                <label class="col-form-label col-sm-2 text-right" title="流程流转条件判断变量" style="width:28%;">关联流程变量：</label>
                <div class="col-sm-8"  style="width:72%;">
                    <select id="varName" name="varName" class="form-control select2bs4" >


                    </select>
                </div>
            </div>
            <div style="overflow-x:auto;">
                <table id="contentTable" class="table table-head-fixed table-bordered table-hover" cellspacing="0" width="100%">
                    <thead><tr>
                        <th title="流程节点ID">节点ID</th>
                        <th title="流程节点名称">节点名称</th>
                        <th title="是否只读">是否只读</th>
                        <th title="是否必填">是否必填</th>
                        <th title="是否隐藏">是否隐藏</th>
                        </tr></thead>
                    <tbody>
                    <% for(task in fieldAuthorize.taskNodeList) {
                    var index = taskLP.index-1;
                    %>
                    <tr>
                    <td nowrap="nowrap">
                        <input type="hidden" name="taskNodeList[${index}].id" value="${task.id}"/>
                        <input type="hidden" name="taskNodeList[${index}].modelId" value="${task.modelId}"/>
                        <input type="hidden" name="taskNodeList[${index}].modelKey" value="${task.modelKey}"/>
                        <input type="hidden" name="taskNodeList[${index}].modelVersion" value="${task.modelVersion}"/>
                        <input type="hidden" name="taskNodeList[${index}].resourceId" value="${task.resourceId}"/>
                        <input type="hidden" name="taskNodeList[${index}].resourceName" value="${task.resourceName}"/>
                        <input type="hidden" name="taskNodeList[${index}].fieldName" value="${fieldAuthorize.fieldName}"/>
                        ${task.resourceId}
                    </td>
                    <td>
                        ${task.resourceName}
                    </td>
                    <td>
                        <input type="checkbox" name="taskNodeList[${index}].isRead" value="1" ${task.isRead=='1' ? 'checked="checked" ' : ''} class="form-control "/>
                    </td>
                    <td>
                        <input type="checkbox" name="taskNodeList[${index}].isRequire" value="1" ${task.isRequire =='1' ? 'checked="checked"' : ''} class="form-control "/>
                    </td>
                    <td>
                        <input type="checkbox" name="taskNodeList[${index}].isHide" value="1" ${task.isHide=='1' ? 'checked="checked"' : ''} class="form-control "/>
                    </td>
                    </tr>
                    <% } %>
                    </tbody>
                </table>
            </div>
        </div>
    </form>
</div>
<% } %>

<script type="text/javascript">
    $("#inputForm").validate({
        submitHandler: function(form){
            $("input[type=checkbox]").each(function(){
                $(this).after("<input type=\"hidden\" name=\""+$(this).attr("name")+"\" value=\""
                    +($(this).is(':checked')?"1":"0")+"\"/>");
                $(this).attr("name", "_"+$(this).attr("name"));
            });

            js.ajaxSubmitForm($(form));
        }
    });

    $(document).ready(function(){
        <% var vars = @JsonMapper.toJsonString(varList); %>
        $("#varName").append("<option></option>");
        $.each(${vars}, function(index,item){
            var opCheck = "";
            var selVar = "${fieldAuthorize.varName}";
            js.print("selVar==" + selVar);
            js.print("item==" + item);
            if(selVar == item) {
                opCheck = "selected='selected'";
            }
            $("#varName").append("<option value='" + item + "'" + opCheck + ">" + item + "</option>");
        });
    });

</script>
